from PyQt5.QtGui import QColor
from PyQt5.QtWidgets import QWidget
from qfluentwidgets import (RoundMenu, Action, setFont,  AvatarWidget, isDarkTheme, BodyLabel, CaptionLabel, HyperlinkButton)
from qfluentwidgets.components.navigation import NavigationAvatarWidget
from qfluentwidgets import FluentIcon


class ProfileCard(QWidget):

    def __init__(self, avatarPath: str, name: str, email: str, parent=None):
        super().__init__(parent=parent)
        self.avatar = AvatarWidget(avatarPath, self)
        self.nameLabel = BodyLabel(name, self)
        self.emailLabel = CaptionLabel(email, self)
        self.logoutButton = HyperlinkButton(
            'https://www.douyin.com', '注销', self)

        color = QColor(206, 206, 206) if isDarkTheme() else QColor(96, 96, 96)
        self.emailLabel.setStyleSheet('QLabel{color: '+color.name()+'}')

        color = QColor(255, 255, 255) if isDarkTheme() else QColor(0, 0, 0)
        self.nameLabel.setStyleSheet('QLabel{color: '+color.name()+'}')
        setFont(self.logoutButton, 13)

        self.setFixedSize(307, 82)
        self.avatar.setRadius(24)
        self.avatar.move(2, 6)
        self.nameLabel.move(64, 13)
        self.emailLabel.move(64, 32)
        self.logoutButton.move(52, 48)


class NavigationInterface(NavigationAvatarWidget):
    def __init__(self):
        self.name = 'chenliang'
        self.avatar = 'resource/image/touxiang.jpg'
        self.email = 'cleverlove8@outlook.com'
        super().__init__(name=self.name, avatar=self.avatar)
        self.setObjectName("Navigation")

    def contextMenuEvent(self, e) -> None:
        menu = RoundMenu(parent=self)

        # add custom widget
        card = ProfileCard(self.avatar, self.name, self.email, menu)
        menu.addWidget(card, selectable=False)
        # menu.addWidget(card, selectable=True, onClick=lambda: print('666'))

        menu.addSeparator()
        menu.addActions([
            Action(FluentIcon.PEOPLE, '管理账户和设置'),
            Action(FluentIcon.SHOPPING_CART, '支付方式'),
            Action(FluentIcon.CODE, '兑换代码和礼品卡'),
        ])
        menu.addSeparator()
        menu.addAction(Action(FluentIcon.SETTING, '设置'))
        menu.exec(e.globalPos())
